from django.db import models

def MBID():
    """Return a field representing a MusicBrainz ID.

    MBIDs are in fact UUIDs, so always exactly 36 chars long.
    """
    return models.CharField(max_length=36, blank=True,
                            default='', db_index=True)

class Artist(models.Model):
    mbid = MBID()

    name = models.CharField(max_length=100, unique=True, db_index=True)

class Album(models.Model):
    mbid = MBID()

    name = models.CharField(max_length=100, db_index=True)
    artist = models.ForeignKey(Artist)

class Track(models.Model):
    mbid = MBID()

    name = models.CharField(max_length=100, db_index=True)
    artist = models.ForeignKey(Artist)
    album = models.ForeignKey(Album, blank=True)

    replay_gain = models.CharField(max_length=10)
    tags = models.ManyToManyField('TrackTag')

    # Path component under the music root.
    file = models.CharField(max_length=300, unique=True)
    live = models.BooleanField(default=False)

class TrackTag(models.Model):
    name = models.CharField(max_length=32, db_index=True, unique=True)
